
#include "IPlus.h"

extern long g_nComObjsInUse;
class CPlusObj : public IPlus
{
public:
	//Implement unknown interface
	HRESULT __stdcall QueryInterface(
		REFIID riid , 
		void **ppObj);


	ULONG   __stdcall AddRef()
	{
		return InterlockedIncrement(&m_nRefCount) ;
	}

	ULONG   __stdcall Release()
	{     
		long nRefCount=0;
		nRefCount=InterlockedDecrement(&m_nRefCount) ;
		if (nRefCount == 0) delete this;
		return nRefCount;
	}

	//implement IPlus interface
	HRESULT __stdcall setFirtNumber( long nX1);
	HRESULT __stdcall setSecondNumber( long nX2);
	HRESULT __stdcall DoPlus( long *pBuffer);


	CPlusObj()
	{
		//
		//constructor
		//

		m_nRefCount=0;
		
		//
		//increment the global count
		//
		InterlockedIncrement(&g_nComObjsInUse);

		
	}


	~CPlusObj()
	{
		
		//destructor
		//incerement the global object count
		InterlockedDecrement(&g_nComObjsInUse);

	}
private:
	long m_nRefCount;   //for managing the reference count

	long m_nX;
	long m_nY;
};